package ui.activity.mine;

import android.os.Bundle;
import android.view.View;

import com.dispatchapp.andlei.BuildConfig;
import com.dispatchapp.andlei.R;
import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;

import java.util.HashMap;
import java.util.Map;

import base.activity.BaseLayoutActivity;
import utils.GsonUtils;
import utils.SPUtils;

/**
 * 收支明细
 * @author Andlei
 * @DATE 2019/1/22
 */
public class ReceiptsDetailsActivity extends BaseLayoutActivity {
//    private SwipeRefreshLayout swipeRefreshLayout;
//    private RecyclerView recyclerView;
//    private TextView tv_finish_order,tv_hasdao_order,tv_daidao_order,tv_zhichu_order;
//    private MyWalletAdapter walletAdapter;
//    private List<MultipleItem> itemList = new ArrayList<>();
//    private ReceiptsDetailsAdapter adapter;
//    private List<ReceiptsDetailsBean> list = new ArrayList<>();
//    private NetUtils netUtils;
    private BridgeWebView webView;
    private String url = BuildConfig.H5_BASE_URL;
//    private int page = 0;
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setTitle("收支明细",true);
//        setTitlefontBg_black();
//    }
//    @Override
//    protected void onResume() {
//        super.onResume();
//        setTitlefontBg_black();
//    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_receipts_details;
    }

    @Override
    protected void findViews() {
//        netUtils = new NetUtils(mActivity,netRequestCallBack);
//        tv_finish_order = getView(R.id.tv_zhichu_order);
//        tv_hasdao_order = getView(R.id.tv_hasdao_order);
//        tv_daidao_order = getView(R.id.tv_daidao_order);
//        tv_zhichu_order = getView(R.id.tv_zhichu_order);
//        swipeRefreshLayout = getView(R.id.swipe_refres);
//        recyclerView = getView(R.id.list_rcy);
        webView = getView(R.id.web_view);

        webView.loadUrl(url);
        webView.registerHandler("loginStatus", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                Map<String,Object> map = new HashMap<>();
                map.put("Authorization", SPUtils.getInstance(mContext).getString("token").substring(1,SPUtils.getInstance(mContext).getString("token").length()-1));
                map.put("ua",SPUtils.getUa(true));
                String sdata = GsonUtils.beanToJSONString(map);
                function.onCallBack(sdata);
            }
        });
        webView.registerHandler("goBack", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                finish();
            }
        });
    }

    @Override
    protected void formatViews() {
//        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
//        layoutManager.setOrientation(LinearLayout.VERTICAL);
//        recyclerView.setLayoutManager(layoutManager);

//        for (int i = 0;i<10;i++){
//            MultipleItem item;
//            if(i<5){
//                item = new MultipleItem(1);
//
//            }else {
//                item = new MultipleItem(2);
//            }
//            itemList.add(item);
//        }
//        walletAdapter = new MyWalletAdapter(itemList);
//        walletAdapter.bindToRecyclerView(recyclerView);
//        recyclerView.setAdapter(walletAdapter);
//        walletAdapter.setEmptyView(R.layout.empty_view);
//        TextView textView =  walletAdapter.getEmptyView().findViewById(R.id.tv_empty);
//        textView.setText("暂时没有明细哦");

//        adapter = new ReceiptsDetailsAdapter(R.layout.item_receipts_detail,list);
//        adapter.bindToRecyclerView(recyclerView);
//        recyclerView.setAdapter(adapter);
//        adapter.setEmptyView(R.layout.empty_view);
//        TextView textView =  adapter.getEmptyView().findViewById(R.id.tv_empty);
//        textView.setText("暂时没有明细哦");

        //下拉刷新
//        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                // lists.clear();
//                page = 0;
//                loaddata();
//            }
//        });
        //上拉加载
//        walletAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
//            @Override
//            public void onLoadMoreRequested() {
//                recyclerView.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        loaddata();
//                    }
//                }, 500);
//
//            }
//        });
//        adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
//            @Override
//            public void onLoadMoreRequested() {
//                recyclerView.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        loaddata();
//                    }
//                }, 500);
//
//            }
//        });
    }
//    private void loaddata(){
//        Map<String,Object> map = new HashMap<>();
//        map.put("page",page);
//        map.put("limit","10");
//        netUtils.get("rider/user/wallet-list",map,BaseBean.class,null,false);
//    }
    @Override
    protected void formatData() {
//        loaddata();
    }

    @Override
    protected void getBundle(Bundle bundle) {

    }

    @Override
    public void onClick(View view) {

    }
//    private NetUtils.NetRequestCallBack netRequestCallBack = new NetUtils.NetRequestCallBack() {
//        @Override
//        public void error(String action, Throwable e, Map tag) {
//            swipeRefreshLayout.setRefreshing(false);
//            adapter.loadMoreComplete();
////            walletAdapter.loadMoreComplete();
//        }
//
//        @Override
//        public void success(String action, BaseBean t, Map tag) {
//            swipeRefreshLayout.setRefreshing(false);
//            if(t.getCode() == 200){
//                if(page ==0){
//                    list.clear();
//                    list = GsonUtils.getInstance(mActivity).parseNoHeaderJArray(t,ReceiptsDetailsBean.class);
//                    adapter.setNewData(list);
////                    walletAdapter.setNewData(itemList);
//                    page=1;
//                }else {
//                    if(list.size()>=t.getCount()){
//                        adapter.loadMoreEnd();
////                        walletAdapter.loadMoreEnd();
//                    }else {
//                        list.addAll(GsonUtils.getInstance(mActivity).parseNoHeaderJArray(t,ReceiptsDetailsBean.class));
//                        adapter.notifyDataSetChanged();
////                        walletAdapter.notifyDataSetChanged();
//                        page++;
//                        adapter.loadMoreComplete();
////                        walletAdapter.loadMoreComplete();
//                    }
//
//                }
//            }else {
//
//            }
//        }
//    };
}
